
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Django入门与实践-第15章：用户注销 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Authentication2.html" />
    
    
    <link rel="prev" href="Authentication0.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="GettingStarted.html">
            
                <a href="GettingStarted.html">
            
                    
                    Django入门与实践-第1章：环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="GettingStarted-2.html">
            
                <a href="GettingStarted-2.html">
            
                    
                    Django入门与实践-第2章：创建项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="gettingstarted-3.html">
            
                <a href="gettingstarted-3.html">
            
                    
                    Django入门与实践-第3章：Hello World
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Fundamentals-1.html">
            
                <a href="Fundamentals-1.html">
            
                    
                    Django入门与实践-第4章：系统设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="Fundamentals-2.html">
            
                <a href="Fundamentals-2.html">
            
                    
                    Django入门与实践-第5章：模型设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="Fundamentals-3-0.html">
            
                <a href="Fundamentals-3-0.html">
            
                    
                    Django入门与实践-第6章：第一个视图函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="Fundamentals-3-1.html">
            
                <a href="Fundamentals-3-1.html">
            
                    
                    Django入门与实践-第7章：模板引擎设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="Fundamentals-3-1-1.html">
            
                <a href="Fundamentals-3-1-1.html">
            
                    
                    Django入门与实践-第8章：第一个单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="Fundamentals-3-2.html">
            
                <a href="Fundamentals-3-2.html">
            
                    
                    Django入门与实践-第9章：静态文件设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="Fundamentals-4.html">
            
                <a href="Fundamentals-4.html">
            
                    
                    Django入门与实践-第10章：Django Admin 介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="AdvancedConcepts.html">
            
                <a href="AdvancedConcepts.html">
            
                    
                    Django入门与实践-第11章：URL 分发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="AdvancedConcept2.html">
            
                <a href="AdvancedConcept2.html">
            
                    
                    Django入门与实践-第12章：复用模板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="AdvancedConcept3.html">
            
                <a href="AdvancedConcept3.html">
            
                    
                    Django入门与实践-第13章：表单处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="Authentication0.html">
            
                <a href="Authentication0.html">
            
                    
                    Django入门与实践-第14章：用户注册
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.16" data-path="Authentication1.html">
            
                <a href="Authentication1.html">
            
                    
                    Django入门与实践-第15章：用户注销
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="Authentication2.html">
            
                <a href="Authentication2.html">
            
                    
                    Django入门与实践-第16章：用户登录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="DjangoORM0.html">
            
                <a href="DjangoORM0.html">
            
                    
                    Django入门与实践-第17章：保护视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="DjangoORM1.html">
            
                <a href="DjangoORM1.html">
            
                    
                    Django入门与实践-第18章：实现主题回复列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="DjangoORM2.html">
            
                <a href="DjangoORM2.html">
            
                    
                    Django入门与实践-第19章：实现主题回复功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="DjangoORM3.html">
            
                <a href="DjangoORM3.html">
            
                    
                    Django入门与实践-第20章：查询结果集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="DjangoORM.html">
            
                <a href="DjangoORM.html">
            
                    
                    Django入门与实践-第21章：Django数据迁移
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="ClassBasedViews0.html">
            
                <a href="ClassBasedViews0.html">
            
                    
                    Django入门与实践-第22章：基于类的视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="ClassBasedViews1.html">
            
                <a href="ClassBasedViews1.html">
            
                    
                    Django入门与实践-第23章：分页实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="ClassBasedViews2.html">
            
                <a href="ClassBasedViews2.html">
            
                    
                    Django入门与实践-第24章：我的账户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="ClassBasedViews3.html">
            
                <a href="ClassBasedViews3.html">
            
                    
                    Django入门与实践-第25章：Markdown支持
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.27" data-path="ClassBasedViews4.html">
            
                <a href="ClassBasedViews4.html">
            
                    
                    Django入门与实践-第26章：个性化设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="Deployment.html">
            
                <a href="Deployment.html">
            
                    
                    Django入门与实践-第27章：项目部署
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Django入门与实践-第15章：用户注销</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="django&#x5165;&#x95E8;&#x4E0E;&#x5B9E;&#x8DF5;-&#x7B2C;15&#x7AE0;&#xFF1A;&#x7528;&#x6237;&#x6CE8;&#x9500;">Django&#x5165;&#x95E8;&#x4E0E;&#x5B9E;&#x8DF5;-&#x7B2C;15&#x7AE0;&#xFF1A;&#x7528;&#x6237;&#x6CE8;&#x9500;</h1>
<p>&#x4E3A;&#x4E86;&#x5728;&#x5B9E;&#x73B0;&#x8FC7;&#x7A0B;&#x4FDD;&#x6301;&#x5B8C;&#x6574;&#x81EA;&#x7136;&#x6D41;&#x7545;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x6DFB;&#x52A0;&#x6CE8;&#x9500;&#x89C6;&#x56FE;&#xFF0C;&#x7F16;&#x8F91;<strong>urls.py</strong>&#x4EE5;&#x6DFB;&#x52A0;&#x65B0;&#x7684;&#x8DEF;&#x7531;&#xFF1A;</p>
<p><strong>myproject/urls.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.conf.urls <span class="hljs-keyword">import</span> url
<span class="hljs-keyword">from</span> django.contrib <span class="hljs-keyword">import</span> admin
<span class="hljs-keyword">from</span> django.contrib.auth <span class="hljs-keyword">import</span> views <span class="hljs-keyword">as</span> auth_views

<span class="hljs-keyword">from</span> accounts <span class="hljs-keyword">import</span> views <span class="hljs-keyword">as</span> accounts_views
<span class="hljs-keyword">from</span> boards <span class="hljs-keyword">import</span> views

urlpatterns = [
    url(<span class="hljs-string">r&apos;^$&apos;</span>, views.home, name=<span class="hljs-string">&apos;home&apos;</span>),
    url(<span class="hljs-string">r&apos;^signup/$&apos;</span>, accounts_views.signup, name=<span class="hljs-string">&apos;signup&apos;</span>),
    url(<span class="hljs-string">r&apos;^logout/$&apos;</span>, auth_views.LogoutView.as_view(), name=<span class="hljs-string">&apos;logout&apos;</span>),
    url(<span class="hljs-string">r&apos;^boards/(?P&lt;pk&gt;\d+)/$&apos;</span>, views.board_topics, name=<span class="hljs-string">&apos;board_topics&apos;</span>),
    url(<span class="hljs-string">r&apos;^boards/(?P&lt;pk&gt;\d+)/new/$&apos;</span>, views.new_topic, name=<span class="hljs-string">&apos;new_topic&apos;</span>),
    url(<span class="hljs-string">r&apos;^admin/&apos;</span>, admin.site.urls),
]
</code></pre>
<p>&#x6211;&#x4EEC;&#x4ECE;Django&#x7684;contrib&#x6A21;&#x5757;&#x5BFC;&#x5165;&#x4E86;<strong>views</strong> &#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5176;&#x66F4;&#x540D;&#x4E3A;<strong>auth_views</strong> &#x4EE5;&#x907F;&#x514D;&#x4E0E;<strong>boards.views</strong>&#x53D1;&#x751F;&#x51B2;&#x7A81;&#x3002;&#x6CE8;&#x610F;&#x8FD9;&#x4E2A;&#x89C6;&#x56FE;&#x6709;&#x70B9;&#x4E0D;&#x540C;&#xFF1A; <code>LogoutView.as_view()</code>&#x3002;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;Django&#x7684;&#x201C;&#x57FA;&#x4E8E;&#x7C7B;&#x201D;&#x7684;&#x89C6;&#x56FE;&#xFF0C;&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x5C06;&#x7C7B;&#x5B9E;&#x73B0;&#x4E3A;python&#x51FD;&#x6570;&#x3002;&#x57FA;&#x4E8E;&#x7C7B;&#x7684;&#x89C6;&#x56FE;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x66F4;&#x52A0;&#x7075;&#x6D3B;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x6269;&#x5C55;&#x548C;&#x91CD;&#x7528;&#x89C6;&#x56FE;&#x3002;&#x7A0D;&#x540E;&#x6211;&#x4EEC;&#x5C06;&#x8BA8;&#x8BBA;&#x66F4;&#x591A;&#x8FD9;&#x4E2A;&#x4E3B;&#x9898;&#x3002;</p>
<p>&#x6253;&#x5F00;<strong>settings.py</strong>&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x6DFB;&#x52A0;<code>LOGOUT_REDIRECT_URL</code>&#x53D8;&#x91CF;&#x5230;&#x6587;&#x4EF6;&#x7684;&#x5E95;&#x90E8;&#xFF1A;</p>
<p><strong>myproject/settings.py</strong></p>
<pre><code>LOGOUT_REDIRECT_URL = &apos;home&apos;
</code></pre><p>&#x5728;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x7ED9;&#x53D8;&#x91CF;&#x6307;&#x5B9A;&#x4E86;&#x4E00;&#x4E2A;URL&#x6A21;&#x578B;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x4EE5;&#x544A;&#x8BC9;Django&#x5F53;&#x7528;&#x6237;&#x9000;&#x51FA;&#x767B;&#x5F55;&#x4E4B;&#x540E;&#x8DF3;&#x8F6C;&#x7684;&#x5730;&#x5740;&#x3002;</p>
<p>&#x5728;&#x8FD9;&#x4E4B;&#x540E;&#xFF0C;&#x8FD9;&#x6B21;&#x91CD;&#x5B9A;&#x5411;&#x5C31;&#x7B97;&#x5B8C;&#x6210;&#x4E86;&#x3002;&#x53EA;&#x9700;&#x8981;&#x8BBF;&#x95EE;URL <strong>127.0.0.1:8000/logout/</strong> &#x7136;&#x540E;&#x60A8;&#x5C31;&#x5C06;&#x88AB;&#x6CE8;&#x9500;&#x3002;&#x4F46;&#x662F;&#x518D;&#x7B49;&#x4E00;&#x4E0B;&#xFF0C;&#x5728;&#x4F60;&#x6CE8;&#x9500;&#x4E4B;&#x524D;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x4E3A;&#x767B;&#x5F55;&#x7528;&#x6237;&#x521B;&#x5EFA;&#x4E0B;&#x62C9;&#x83DC;&#x5355;&#x3002;</p>
<hr>
<h4 id="&#x4E3A;&#x767B;&#x5F55;&#x7528;&#x6237;&#x663E;&#x793A;&#x83DC;&#x5355;">&#x4E3A;&#x767B;&#x5F55;&#x7528;&#x6237;&#x663E;&#x793A;&#x83DC;&#x5355;</h4>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728; <strong>base.html</strong>&#x6A21;&#x677F;&#x4E2D;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x8C03;&#x6574;&#x3002;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5E26;&#x6CE8;&#x9500;&#x94FE;&#x63A5;&#x7684;&#x4E0B;&#x62C9;&#x83DC;&#x5355;&#x3002;</p>
<p>Bootstrap 4 &#x4E0B;&#x62C9;&#x7EC4;&#x4EF6;&#x9700;&#x8981;jQuery&#x624D;&#x80FD;&#x5DE5;&#x4F5C;&#x3002;     </p>
<p>&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x524D;&#x5F80; <a href="https://jquery.com/download/" target="_blank">jquery.com/download/</a>&#xFF0C;&#x7136;&#x540E;&#x4E0B;&#x8F7D;&#x538B;&#x7F29;&#x7684; jQuery 3.2.1&#x7248;&#x672C;&#x3002;</p>
<p><img src="statics/jquery-download.jpg" alt="jQuery Download"></p>
<p>&#x5728;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;js&#x7684;&#x65B0;&#x6587;&#x4EF6;&#x5939;&#x3002;&#x5C06;jquery-3.2.1.min.js&#x6587;&#x4EF6;&#x590D;&#x5236;&#x5230;&#x90A3;&#x91CC;&#x3002;</p>
<p>Bootstrap4&#x8FD8;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;<strong>Popper</strong> &#x7684;&#x5E93;&#x624D;&#x80FD;&#x5DE5;&#x4F5C;&#xFF0C;&#x524D;&#x5F80; <a href="https://popper.js.org/" target="_blank">popper.js.org</a> &#x4E0B;&#x8F7D;&#x5B83;&#x7684;&#x6700;&#x65B0;&#x7248;&#x672C;&#x3002;</p>
<p>&#x5728;<strong>popper.js-1.12.5</strong>&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#xFF0C;&#x8F6C;&#x5230;<strong>dist/umd</strong>&#x5E76;&#x5C06;&#x6587;&#x4EF6;<strong>popper.min.js</strong> &#x590D;&#x5236;&#x5230;&#x6211;&#x4EEC;&#x7684;<strong>js</strong> &#x6587;&#x4EF6;&#x5939;&#x3002;&#x8FD9;&#x91CC;&#x6CE8;&#x610F;&#xFF0C;&#x6572;&#x9ED1;&#x677F;&#xFF01;Bootstrap 4&#x53EA;&#x80FD;&#x4E0E; <strong>umd/popper.min.js</strong>&#x534F;&#x540C;&#x5DE5;&#x4F5C;&#x3002;&#x6240;&#x4EE5;&#x8BF7;&#x786E;&#x4FDD;&#x4F60;&#x6B63;&#x5728;&#x590D;&#x5236;&#x6B63;&#x786E;&#x7684;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x5982;&#x679C;&#x60A8;&#x4E0D;&#x518D;&#x62E5;&#x6709; Bootstrap 4&#x6587;&#x4EF6;&#xFF0C;&#x8BF7;&#x4ECE;<a href="http://getbootstrap.com/" target="_blank">getbootstrap.com</a>.&#x518D;&#x6B21;&#x4E0B;&#x8F7D;&#x5B83;&#x3002;</p>
<p>&#x540C;&#x6837;&#xFF0C;&#x5C06; <strong>bootstrap.min.js</strong>&#x6587;&#x4EF6;&#x590D;&#x5236;&#x5230;&#x6211;&#x4EEC;&#x7684;js&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x3002;&#x6700;&#x7EC8;&#x7684;&#x7ED3;&#x679C;&#x5E94;&#x8BE5;&#x662F;&#xFF1A;</p>
<pre><code class="lang-shell">myproject/
 |-- myproject/
 |    |-- accounts/
 |    |-- boards/
 |    |-- myproject/
 |    |-- static/
 |    |    |-- css/
 |    |    +-- js/
 |    |         |-- bootstrap.min.js
 |    |         |-- jquery-3.2.1.min.js
 |    |         +-- popper.min.js
 |    |-- templates/
 |    |-- db.sqlite3
 |    +-- manage.py
 +-- venv/
</code></pre>
<p>&#x5728;<strong>base.html</strong>&#x6587;&#x4EF6;&#x5E95;&#x90E8;&#xFF0C;&#x5728;{% endblock body %}&#x540E;&#x9762;&#x6DFB;&#x52A0;&#x811A;&#x672C;&#xFF1A;</p>
<p><strong>templates/base.html</strong></p>
<pre><code class="lang-html">{% load static %}<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;utf-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>{% block title %}Django Boards{% endblock %}<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;https://fonts.googleapis.com/css?family=Peralta&quot;</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% static &apos;css/bootstrap.min.css&apos; %}&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% static &apos;css/app.css&apos; %}&quot;</span>&gt;</span>
    {% block stylesheet %}{% endblock %}
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    {% block body %}
    <span class="hljs-comment">&lt;!-- code suppressed for brevity --&gt;</span>
    {% endblock body %}
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;{% static &apos;js/jquery-3.2.1.min.js&apos; %}&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;{% static &apos;js/popper.min.js&apos; %}&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;{% static &apos;js/bootstrap.min.js&apos; %}&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>&#x5982;&#x679C;&#x4F60;&#x53D1;&#x73B0;&#x4E0A;&#x9762;&#x7684;&#x8BF4;&#x660E;&#x5F88;&#x6A21;&#x7CCA;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x76F4;&#x63A5;&#x5728;&#x4E0B;&#x9762;&#x7684;&#x94FE;&#x63A5;&#x4E0B;&#x8F7D;&#x6587;&#x4EF6;</p>
<ul>
<li><a href="https://code.jquery.com/jquery-3.2.1.min.js" target="_blank">https://code.jquery.com/jquery-3.2.1.min.js</a></li>
<li><a href="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" target="_blank">https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js</a></li>
<li><a href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" target="_blank">https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js</a></li>
</ul>
<p>&#x6253;&#x5F00;&#x94FE;&#x63A5;&#xFF0C;&#x53F3;&#x952E;&#x53E6;&#x5B58;&#x4E3A;</p>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6DFB;&#x52A0;Bootstrap4&#x4E0B;&#x62C9;&#x83DC;&#x5355;&#x4E86;&#xFF1A;</p>
<p><strong>templates/base.html</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar navbar-expand-sm navbar-dark bg-dark&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-brand&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;home&apos; %}&quot;</span>&gt;</span>Django Boards<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-toggler&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;button&quot;</span> <span class="hljs-attr">data-toggle</span>=<span class="hljs-string">&quot;collapse&quot;</span> <span class="hljs-attr">data-target</span>=<span class="hljs-string">&quot;#mainMenu&quot;</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">&quot;mainMenu&quot;</span> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">&quot;false&quot;</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">&quot;Toggle navigation&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-toggler-icon&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;collapse navbar-collapse&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;mainMenu&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-nav ml-auto&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;nav-item dropdown&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;nav-link dropdown-toggle&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;userMenu&quot;</span> <span class="hljs-attr">data-toggle</span>=<span class="hljs-string">&quot;dropdown&quot;</span> <span class="hljs-attr">aria-haspopup</span>=<span class="hljs-string">&quot;true&quot;</span> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">&quot;false&quot;</span>&gt;</span>
            {{ user.username }}
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-menu dropdown-menu-right&quot;</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">&quot;userMenu&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-item&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span>&gt;</span>My account<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-item&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span>&gt;</span>Change password<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-divider&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-item&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;logout&apos; %}&quot;</span>&gt;</span>Log out<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
<p><img src="statics/dropdown.png" alt="Dropdown menu"></p>
<p>&#x6211;&#x4EEC;&#x6765;&#x8BD5;&#x8BD5;&#x5427;&#xFF0C;&#x70B9;&#x51FB;&#x6CE8;&#x9500;&#xFF1A;</p>
<p><img src="statics/logout.png" alt="Logout"></p>
<p>&#x73B0;&#x5728;&#x5DF2;&#x7ECF;&#x6210;&#x529F;&#x663E;&#x793A;&#x51FA;&#x6765;&#x4E86;&#xFF0C;&#x4F46;&#x662F;&#x65E0;&#x8BBA;&#x7528;&#x6237;&#x767B;&#x5F55;&#x4E0E;&#x5426;&#xFF0C;&#x4E0B;&#x62C9;&#x83DC;&#x5355;&#x90FD;&#x4F1A;&#x663E;&#x793A;&#x3002;&#x4E0D;&#x540C;&#x7684;&#x662F;&#x5728;&#x672A;&#x767B;&#x5F55;&#x65F6;&#x7528;&#x6237;&#x540D;&#x663E;&#x793A;&#x662F;&#x7A7A;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x80FD;&#x770B;&#x5230;&#x4E00;&#x4E2A;&#x7BAD;&#x5934;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6539;&#x8FDB;&#x4E00;&#x70B9;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar navbar-expand-sm navbar-dark bg-dark&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-brand&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;home&apos; %}&quot;</span>&gt;</span>Django Boards<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-toggler&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;button&quot;</span> <span class="hljs-attr">data-toggle</span>=<span class="hljs-string">&quot;collapse&quot;</span> <span class="hljs-attr">data-target</span>=<span class="hljs-string">&quot;#mainMenu&quot;</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">&quot;mainMenu&quot;</span> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">&quot;false&quot;</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">&quot;Toggle navigation&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-toggler-icon&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;collapse navbar-collapse&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;mainMenu&quot;</span>&gt;</span>
      {% if user.is_authenticated %}
        <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-nav ml-auto&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;nav-item dropdown&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;nav-link dropdown-toggle&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;userMenu&quot;</span> <span class="hljs-attr">data-toggle</span>=<span class="hljs-string">&quot;dropdown&quot;</span> <span class="hljs-attr">aria-haspopup</span>=<span class="hljs-string">&quot;true&quot;</span> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">&quot;false&quot;</span>&gt;</span>
              {{ user.username }}
            <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-menu dropdown-menu-right&quot;</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">&quot;userMenu&quot;</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-item&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span>&gt;</span>My account<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-item&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span>&gt;</span>Change password<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-divider&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-item&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;logout&apos; %}&quot;</span>&gt;</span>Log out<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      {% else %}
        <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;form-inline ml-auto&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-outline-secondary&quot;</span>&gt;</span>Log in<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;signup&apos; %}&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-primary ml-2&quot;</span>&gt;</span>Sign up<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
      {% endif %}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
<p>&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x544A;&#x8BC9;Django&#x7A0B;&#x5E8F;&#xFF0C;&#x8981;&#x5728;&#x7528;&#x6237;&#x767B;&#x5F55;&#x65F6;&#x663E;&#x793A;&#x4E0B;&#x62C9;&#x83DC;&#x5355;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#xFF0C;&#x5219;&#x663E;&#x793A;&#x767B;&#x5F55;&#x5E76;&#x6CE8;&#x518C;&#x6309;&#x94AE;&#xFF1A;</p>
<p><img src="statics/mainmenu.png" alt="Main Menu"></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Authentication0.html" class="navigation navigation-prev " aria-label="Previous page: Django入门与实践-第14章：用户注册">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Authentication2.html" class="navigation navigation-next " aria-label="Next page: Django入门与实践-第16章：用户登录">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Django入门与实践-第15章：用户注销","level":"1.16","depth":1,"next":{"title":"Django入门与实践-第16章：用户登录","level":"1.17","depth":1,"path":"Authentication2.md","ref":"./Authentication2.md","articles":[]},"previous":{"title":"Django入门与实践-第14章：用户注册","level":"1.15","depth":1,"path":"Authentication0.md","ref":"./Authentication0.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["include-codeblock","livereload"],"pluginsConfig":{"include-codeblock":{"check":false,"edit":false,"fixlang":false,"lang":"","template":"default","theme":"chrome","unindent":false},"livereload":{},"highlight":{},"search":{},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"sharing":{"all":["facebook","google","instapaper","twitter","weibo"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"fontsettings":{"family":"sans","size":2,"theme":"white"},"theme-default":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}},"file":{"path":"Authentication1.md","mtime":"2018-05-13T13:48:46.855Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-05-13T12:52:49.928Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

